package com.nowar.frame.proxy;

import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.Proxy;

/**
 * @Author: 谢无殇。
 * @Date : 2023-01-14 21:24
 */

public class HttpProxyFactoryBean<T> implements FactoryBean<T> {
    private Class<T> proxyInterface;

    public HttpProxyFactoryBean(Class<T> proxyInterface) {
        this.proxyInterface = proxyInterface;
    }

    @Override
    public T getObject() throws Exception {
        // 代理逻辑处理
        return (T) Proxy.newProxyInstance(proxyInterface.getClassLoader(), new Class[]{proxyInterface},
                new HttpProxyInvocationHandler(proxyInterface));

    }

    @Override
    public Class<?> getObjectType() {
        return proxyInterface;
    }
}
